/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_CYCLONEDDS_STATUSMASK_CONVERTER_HPP_
#define _DAL_CYCLONEDDS_STATUSMASK_CONVERTER_HPP_

#include "dds/dds.h"
#include "dal/ret_type.h"
#include "dal/status.h"

#define CYCLONE_DOMAIN_PARTICIPANT_STATUS_MASK (0u)
#define CYCLONE_PUBLISHER_STATUS_MASK (0u)
#define CYCLONE_SUBSCRIBER_STATUS_MASK (DDS_DATA_ON_READERS_STATUS)
#define CYCLONE_TOPIC_STATUS_MASK (DDS_INCONSISTENT_TOPIC_STATUS)

#define CYCLONE_WRITER_STATUS_MASK (DDS_LIVELINESS_LOST_STATUS          |\
                                    DDS_OFFERED_DEADLINE_MISSED_STATUS  |\
                                    DDS_OFFERED_INCOMPATIBLE_QOS_STATUS |\
                                    DDS_PUBLICATION_MATCHED_STATUS)

#define CYCLONE_READER_STATUS_MASK (DDS_SAMPLE_REJECTED_STATUS              |\
                                    DDS_LIVELINESS_CHANGED_STATUS           |\
                                    DDS_REQUESTED_DEADLINE_MISSED_STATUS    |\
                                    DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS   |\
                                    DDS_DATA_AVAILABLE_STATUS               |\
                                    DDS_SAMPLE_LOST_STATUS                  |\
                                    DDS_SUBSCRIPTION_MATCHED_STATUS)

class StatusMaskConverter
{
protected:
    StatusMaskConverter();
    static StatusMaskConverter* singleton_;

public:
    StatusMaskConverter(StatusMaskConverter& other) = delete;
    void operator=(const StatusMaskConverter&) = delete;
    static StatusMaskConverter* GetInstance();

    void ConvertStatusMaskFromDalToCyclonedds(dal_status_mask_t d_mask, uint32_t* c_mask);
    void FilterDomainParticipantStatusMask(uint32_t* c_mask);
    void FilterPublisherStatusMask(uint32_t* c_mask);
    void FilterSubscriberStatusMask(uint32_t* c_mask);
    void FilterTopicStatusMask(uint32_t* c_mask);
    void FilterDataWriterStatusMask(uint32_t* c_mask);
    void FilterDataReaderStatusMask(uint32_t* c_mask);
};

#endif  // _DAL_CYCLONEDDS_STATUSMASK_CONVERTER_HPP_